package jdk;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
public class Print {
	static class WrapperBool{
		public boolean f = true;
	}
	public static void main(String[] args) {
		ReentrantLock lock = new ReentrantLock();
		Condition t1print = lock.newCondition();
		Condition t2print = lock.newCondition();
		final WrapperBool wb = new WrapperBool();
		Thread t1 = new Thread(new Runnable(){
			@Override
			public void run() {
				for(int i=1;i<=52;){
					lock.lock();
					try{
						while(!wb.f){
							t1print.await();
						}
						System.out.print(i++);
						System.out.print(i++);
						wb.f = false;
						t2print.signal();
					}catch(Exception e){
						e.printStackTrace();
					}finally{
						lock.unlock();
					}
				}
			}
		},"thread1");
		Thread t2 = new Thread(new Runnable(){
			public void run() {
				for(char i ='A';i<='Z';i++){
					lock.lock();
					try{
						while(wb.f){
							t2print.await();
						}
						System.out.print(i);
						wb.f = true;
						t1print.signal();
					}catch(Exception e){
						e.printStackTrace();
					}finally{
						lock.unlock();
					}
				}
			}
		},"thread2");
		t1.start();
		t2.start();
//		System.out.println("");
	}

}
